Welcome

Best Practices and Strategies to Create Effective Visualizations

Aaron R. Williams

@awunderground

urban-logo

Best Practices and Strategies to Create Effective Visualizations

Why I Use R

Aaron Williams

@awunderground

urban-logo

Outline

  1. WHY: Principles for selecting a data viz tool
  2. WHAT: R and ggplot2
  3. HOW: The theory behind R and ggplot2
  4. Examples
  5. Grade my decision

WHY: Principles for selecting a data viz tool

1. Looks good!

ledecky

Source: fivethirtyeight

2. Flexible and expressive

3. Reproducible

4. Scalable

AKA “Please just don’t make me point-and-click 100 charts”

cat

5. In my analysis workflow

parallel

WHAT: R and ggplot2

Source: Hadley Wickham

Source: ggplot2

fivethirtyeight

Financial Times

BBC

BBC R Cookbook

HOW: Grammar of Graphics

Leland Wilkinson

Grammar of Graphics

Hadley Wickham

A Layered Grammar of Graphics

hadley

Source: Hadley Wickham

1. Data

name year category lat long wind pressure
Richard 2010 1 17.0 -87.3 80 984
Erin 2001 3 33.3 -63.3 105 969
Barry 1995 0 38.7 -66.0 50 996
Edouard 1990 0 39.6 -28.1 35 1006
Olga 2001 0 30.3 -49.5 50 989
Felix 1989 0 33.8 -43.9 35 1005
Ernesto 2006 0 21.6 -77.4 35 1007
Fabian 1997 0 29.2 -57.9 35 1005
Lili 1996 0 42.3 -33.2 60 980
Klaus 1990 0 16.8 -60.7 55 997

ggplot(data = )

2. Aesthetic mappings

aes(x = , y = , color = )

X or Y

Color or Fill

Aesthetic mappings

Size

Shape

Others: transparency, animations, faceting

3. Geometric objects

Plots are often called their geometric object(s).

Bar

geom_bar()

3. Geometric objects

Line

geom_line()

3. Geometric objects

Point

geom_point()

3. Geometric objects

?

3. Geometric objects

Path of Hurricane Katrina

4. Scales

Before

scale_x_continuous()

After

scale_x_log10()

4. Scales

Before

scale_size_continuous(breaks = c(25, 75, 125))

After

scale_size_continuous(range = c(0.5, 20), breaks = c(25, 75, 125))

5. Coordinate systems

Cartesian

5. Coordinate systems

Polar

coord_polar()

6. Facets (optional)

Facet wrap

facet_wrap(~category)

6. Facets (optional)

Facet grid

facet_grid(month~status)

7. Statistical transformations (optional)

Count

8. Themes

Default theme

8. Themes

fivethirtyeight theme

8. Themes

urbnthemes

Coding example

stop

New? 9. Arrangements

arrangement

New? 9. Arrangements

arrangement

Source: Policyviz by Jon Schwabish

New? 9. Arrangements

Animation

houston

By Sarah Strochak

10. Interactivity?

frontier

Examples

urbnmapr

Pension code

3.2, 4.2, 4.3, 4.7, 5.12

R Shiny

https://www.urban.org/policy-centers/cross-center-initiatives/program-retirement-policy/projects/dynasim-visualizing-older-americans-future-well-being/fiscal-health-social-security

Graphics guide

Strengths and Weaknesses

1. Looks good!

A

2. Flexible and expressive

B

Once you understand ggplot2, it is really useful for doing 90% of the results with 10% of the effort

(Jennfer Hill)

3. Reproducible

A+

4. Scalable

B+

5. In my analysis workflow

A+

Questions